package com.tjsinfo.tjsoa.articles.action;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.articles.bo.IArticlesBO;
import com.tjsinfo.tjsoa.articles.bo.ManageSuperAction;
import com.tjsinfo.tjsoa.articles.bo.TArticlesUserManage;

public class LoginAction extends ManageSuperAction {
	private IArticlesBO articlesBO;
	private String loginName;
	private TArticlesUserManage articlesUserManage;
	
	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public IArticlesBO getArticlesBO() {
		return articlesBO;
	}

	public void setArticlesBO(IArticlesBO articlesBO) {
		this.articlesBO = articlesBO;
	}

	public TArticlesUserManage getArticlesUserManage() {
		return articlesUserManage;
	}

	public void setArticlesUserManage(TArticlesUserManage articlesUserManage) {
		this.articlesUserManage = articlesUserManage;
	}

	@SuppressWarnings("unchecked")
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		loginName="";
		Cookie[] cookies = request.getCookies();
		if(cookies!=null)
		{
		    Integer userID = 1;

		    for (int i = 0; i < cookies.length; i++) 
		    {
		       Cookie c = cookies[i];     
		       if(c.getName().equalsIgnoreCase("RQOAuserId"))
		       {
		    	   userID = Integer.valueOf(c.getValue());
		    	   if(null == articlesUserManage.findById(userID)){
		    		   loginName = "";
		    	   }else{
		    		   loginName = articlesUserManage.findById(userID).getLoginName(); 
		    	   }		   
			request.setAttribute("userID",c.getValue());
		       }
		    } 
		  }
		request.setAttribute("loginName", loginName);
		
		return mapping.findForward("ok");
	}
 
	
}
